其他
PermissionX 1.6发布,支持Android 12,可能是今年最大的版本升级
各位小伙伴们大家早上好。
val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS)
intent.data = Uri.parse("package:${requireActivity().packageName}")
PermissionX.init(activity)
.permissions(Manifest.permission.REQUEST_INSTALL_PACKAGES)
.onExplainRequestReason { scope, deniedList ->
val message = "PermissionX需要您同意以下权限才能正常使用"
scope.showRequestReasonDialog(deniedList, message, "Allow", "Deny")
}
.request { allGranted, grantedList, deniedList ->
if (allGranted) {
Toast.makeText(activity, "所有申请的权限都已通过", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(activity, "您拒绝了如下权限:$deniedList", Toast.LENGTH_SHORT).show()
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.permissionx.app">
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
</manifest>
BLUETOOTH_SCAN 用于使用蓝牙扫描附件其他的蓝牙设备
BLUETOOTH_ADVERTISE 用于允许当前的设备被其他的蓝牙设备所发现
BLUETOOTH_CONNECT 用于连接之前已经配对过的蓝牙设备
<manifest>
<!-- Request legacy Bluetooth permissions on older devices. -->
<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
...
</manifest>
val requestList = ArrayList<String>()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
requestList.add(Manifest.permission.BLUETOOTH_SCAN)
requestList.add(Manifest.permission.BLUETOOTH_ADVERTISE)
requestList.add(Manifest.permission.BLUETOOTH_CONNECT)
}
if (requestList.isNotEmpty()) {
PermissionX.init(activity)
.permissions(requestList)
.explainReasonBeforeRequest()
.onExplainRequestReason { scope, deniedList ->
val message = "PermissionX需要您同意以下权限才能正常使用"
scope.showRequestReasonDialog(deniedList, message, "Allow", "Deny")
}
.request { allGranted, grantedList, deniedList ->
if (allGranted) {
Toast.makeText(activity, "所有申请的权限都已通过", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(activity, "您拒绝了如下权限:$deniedList", Toast.LENGTH_SHORT).show()
}
}
}
repositories {
google()
mavenCentral()
}
dependencies {
implementation 'com.guolindev.permissionx:permissionx:1.6.0'
}
https://github.com/guolindev/PermissionX